package com.test;

import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.ResourceBundle;

public class I18nTest01 {
    @Test
    public void testLocale(){
        //获取默认国家、地区的信息
        Locale locale = Locale.getDefault();
//        System.out.println(locale);
        //获取Java中所有可用的国家、地区信息
        Locale[] availableLocales = Locale.getAvailableLocales();
        for (int i = 0; i < availableLocales.length; i++) {
            System.out.println(availableLocales[i]);
        }
        System.out.println(Locale.CHINA);
        System.out.println(Locale.US);
    }

    @Test
    public void testI18N() throws UnsupportedEncodingException {
        //以中文形式展示
        Locale china = Locale.CHINA;
        //获取对应地区的资源包
        ResourceBundle chineseBundle = ResourceBundle.getBundle("i18n", china);
        System.out.println(new String(chineseBundle.getString("username").getBytes("ISO-8859-1"),"UTF-8") );
        System.out.println(new String(chineseBundle.getString("password").getBytes("ISO-8859-1"),"UTF-8") );
        System.out.println(new String(chineseBundle.getString("login").getBytes("ISO-8859-1"),"UTF-8") );
        System.out.println(chineseBundle.getString("login"));


        Locale US = Locale.US;
        ResourceBundle USBundle = ResourceBundle.getBundle("i18n", US);
        System.out.println(USBundle.getString("username"));
        System.out.println(USBundle.getString("password"));
        System.out.println(USBundle.getString("login"));
    }
}
